package com.cake.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cake.base.util.ReturnUtils;
import com.cake.entity.XxRole;
import com.cake.service.inter.IXxMenuService;
import com.cake.service.inter.IXxRoleService;

/**
 * 角色控制层
 * @author Administrator
 *
 */
@RestController
@RequestMapping(value = "role")
public class RoleController {

		@Autowired
		private IXxRoleService xxRoleService;
		
		@Autowired
		private IXxMenuService xxMenuService;
		
		/**
		 * 查询所有的角色
		 * @return
		 */
		@GetMapping(value = "selectAllRoles")
		public Object selectRoles(){
			return ReturnUtils.forNoramlSuccess(xxRoleService.selectAllRoles());
		}
	
		/**
		 * 通过id查询一个角色详情
		 * @return
		 */
		@GetMapping(value = "selectRoleById")
		public Object selectRoleById(Long roleId){
			return ReturnUtils.forNoramlSuccess(xxRoleService.selectRoleAndMenuByRoleId(roleId));
		}
		
		/**
		 * 添加或者修改角色信息
		 * @return
		 */
		@PostMapping(value = "insertOrUpdateRole")
		public Object insertOrUpdateRole(@RequestBody  XxRole xxRole){
			xxRoleService.insertOrUpdateRole(xxRole);
			return ReturnUtils.forNoraml("000000", "操作成功");
		}
		
		/**
		 * 查询所有的以及菜单
		 * @return
		 */
		@GetMapping(value = "selectFirstGradeMenus")
		public Object selectFirstGradeMenus(){
			return ReturnUtils.forNoramlSuccess(xxMenuService.selectFirstGradeMenus());
		}
		
}
